//
//  MoveiTableViewCell.m
//  Koala_Fm
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MoveiTableViewCell.h"

@implementation MoveiTableViewCell

- (void)dealloc
{
    [_imag release];//视屏播放
    [_headerImage release];//头像
    [_nameLable release];//名字
    [_timeLable release];//时间
    [_texteLable release];// 文字
    [_height release];// 高
    [_width release];// 宽
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.headerImage = [[UIImageView alloc]init];
        //        _headImage.backgroundColor = [UIColor redColor];
        // 切圆
        _headerImage .layer.cornerRadius = 25;
         _headerImage.clipsToBounds = YES;
        
        [self.contentView addSubview: _headerImage];
        [ _headerImage release];
        //
        self.timeLable = [[UILabel alloc]init];
        //                _timeLable.backgroundColor = [UIColor yellowColor];
        _timeLable.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_timeLable];
        [_timeLable release];
        //文字大小
        _nameLable.font = [UIFont systemFontOfSize:15];
        self.nameLable = [[UILabel alloc]init];
        //                _nameLable.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_nameLable];
        [_nameLable release];
        //
        self.imag = [[UIImageView alloc]init];
//        self.imag.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_imag];
        [_imag release];
        //
        self.texteLable = [[UILabel alloc]init];
        self.texteLable.numberOfLines = 0;
        self.textLabel.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_texteLable];
       
        [_texteLable release];
        
        
    }
    return self;
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    _headerImage.frame =CGRectMake(5, 5, 50, 50);
    _nameLable.frame = CGRectMake(60, 5, 150, 20);
    _timeLable.frame = CGRectMake(60, 25, 150, 20);
    CGFloat h = [[self class]heightWithText:_texteLable.text];
    
    _texteLable.frame =CGRectMake(5, 60, self.contentView.frame.size.width  , h);
    
    CGFloat vh = [[self class]heightWithHeight:_height width:_width];
    
    _imag.frame = CGRectMake(5, 60 + h, self.contentView.frame.size.width - 10,vh);
    
}
// 文字自适应高度
+(CGFloat)heightWithText:(NSString *)text{
NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(355, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
// 图片自适应高度
+(CGFloat)heightWithHeight:(NSNumber *)height width:(NSNumber *)width{
    CGFloat h;
    if ([width floatValue] != 0) {
        h = [height floatValue] * 355 / [width floatValue];
    }
    
    return h;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
